package com.tyj.tuyijieapp.config.security.captcha;

import lombok.Data;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * <p>
 * 验证码token
 * </p>
 *
 * @author lhf
 * @since 2020/6/6
 */
public class CaptchaProviderToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = 3469395920515088526L;
    private final Object principal;
    private Object credentials;

    public CaptchaProviderToken(Object principal, Object credentials) {
        super(null);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(false);
    }

    public CaptchaProviderToken(Collection<? extends GrantedAuthority> authorities, Object principal, Object credentials) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(false);
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        credentials = null;
    }
}
